package org.nci.platform.workflow.controller;


import gh.priv.general.common.vo.PageResult;
import gh.priv.general.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.nci.platform.workflow.dto.SysFormPageQuery;
import org.nci.platform.workflow.dto.SysFormQuery;
import org.nci.platform.workflow.entity.SysDeployForm;
import org.nci.platform.workflow.entity.SysForm;
import org.nci.platform.workflow.service.ISysDeployFormService;
import org.nci.platform.workflow.service.ISysFormService;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程表单Controller
 *
 * @author Tony
 * @date 2021-04-03
 */
@Tag(name = "流程表单")
@RestController
@RequestMapping("/flowable/form")
public class SysFormController {
    @Resource
    private ISysFormService sysFormService;

    @Resource
    private ISysDeployFormService sysDeployFormService;

    /**
     * 查询流程表单分页列表
     */
    @Operation(summary = "查询流程表单分页列表")
    @PostMapping("/page")
    public Result<PageResult<SysForm>> page(@RequestBody SysFormPageQuery query) {
        PageResult<SysForm> page = sysFormService.page(query);
        return Result.success(page);
    }
    /**
     * 查询流程表单列表
     */
    @Operation(summary = "查询流程表单列表")
    @PostMapping("/formList")
    public Result<List<SysForm>> formList(@RequestBody SysFormQuery query) {
        List<SysForm> list = sysFormService.list(query);
        return Result.success(list);
    }
    /**
     * 导出流程表单列表
     */
    @Operation(summary = "导出流程表单列表")
    @PostMapping("/export")
    public void export(@RequestBody SysFormQuery query, HttpServletResponse response) {
        sysFormService.export(response,query);
    }

    /**
     * 获取流程表单详细信息
     */
    @Operation(summary = "获取流程表单详细信息")
    @GetMapping(value = "/{formId}")
    public Result<SysForm> getInfo(@PathVariable("formId") Long formId) {
        return Result.success(sysFormService.getById(formId));
    }

    /**
     * 新增流程表单
     */
    @Operation(summary = "新增流程表单")
    @PostMapping
    public Result<Boolean> add(@RequestBody SysForm sysForm) {
        sysFormService.save(sysForm);
        return Result.success();
    }

    /**
     * 修改流程表单
     */
    @Operation(summary = "修改流程表单")
    @PutMapping
    public Result<Boolean> edit(@RequestBody SysForm sysForm) {
        sysFormService.updateById(sysForm);
        return Result.success();
    }

    /**
     * 删除流程表单
     */
    @Operation(summary = "删除流程表单")
    @DeleteMapping("/{formIds}")
    public Result<Boolean> remove(@PathVariable List<Long> formIds) {
        sysFormService.removeByIds(formIds);
        return Result.success();
    }


    /**
     * 挂载流程表单
     */
    @Operation(summary = "挂载流程表单")
    @PostMapping("/addDeployForm")
    public Result<Boolean> addDeployForm(@RequestBody SysDeployForm sysDeployForm) {
        sysDeployFormService.insertSysDeployForm(sysDeployForm);
        return Result.success();
    }
}
